package cn.ziyoufa.smart.smartschool.broadcast;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

/**
 * 创建人 ： 赵泽东
 * 创建时间：2018/9/30
 *
 * @param
 * @param
 */
public class BootReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //开启服务
        String action = intent.getAction();
        if((action.equals(Intent.ACTION_PACKAGE_ADDED)|| action.equals(Intent.ACTION_PACKAGE_REPLACED))){
            Toast.makeText(context,"收到开机广播",Toast.LENGTH_LONG).show();
            startApp(context);
        }
    }

    public void startApp(Context context){
        Intent intent2 = new Intent();
        ComponentName componentName = new ComponentName("cn.ziyoufa.smart.smartschool", "cn.ziyoufa.smart.smartschool.activity.LoadingActivity");
        intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent2.setComponent(componentName);
        context.startActivity(intent2);
    }

}
